﻿using System.Linq.Expressions;
using ToolMonitoring.WebApi.Dependency;
using ToolMonitoring.WebApi.Entities;
using ToolMonitoring.WebApi.Rep;

namespace ToolMonitoring.WebApi.Services
{

	public class UserDemoService:ISingletonDependency
	{
		private readonly UserDemoRepository _userDemoRepository;

		public UserDemoService(UserDemoRepository userDemoRepository)
		{
			_userDemoRepository = userDemoRepository;
		}

		
		public async Task<UserDemo> Add(UserDemo data) 
		{
			_userDemoRepository.Insert(data);
			return await Task.FromResult(data);
		}

		public async Task Update(UserDemo data)
		{
			_userDemoRepository.Update(data);
			await Task.CompletedTask;
		}

		public async Task Remove(Guid id) 
		{
			_userDemoRepository.Delete(id);
			await Task.CompletedTask;
		}

		public async Task Remove(UserDemo data)
		{
			_userDemoRepository.Delete(data.Id);
			await Task.CompletedTask;
		}

		public async Task<UserDemo> FindById(Guid id)
		{
			var result = _userDemoRepository.FindById(id);
			return await Task.FromResult(result);
		}

		public async Task<List<UserDemo>> FindAll()
		{
			var result = _userDemoRepository.FindAll().ToList();
			return await Task.FromResult(result);
		}

		public async Task<List<UserDemo>> Find(Expression<Func<UserDemo, bool>> expression)
		{
			var result = _userDemoRepository.Find(expression).ToList();
			return await Task.FromResult(result);
		}


	}
}
